package com.vstudy.zx.dao.provider;

import com.vstudy.zx.utils.page.ConversationPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class ConversationDaoProvider {
    public String selectByPage(@Param("page") ConversationPage page) {
        String sql = new SQL() {{
            SELECT("*");
            FROM("tb_conversation");
            if (page.getTe_id() != null) {
                WHERE("te_id=#{page.te_id}");
            }
            if (page.getStatus() != null) {
                WHERE("con_status=#{page.status}");
            }
        }}.toString();
        sql += " ORDER BY con_time DESC LIMIT #{page.skip},#{page.pageSize}";
        return sql;
    }

    public String count(@Param("te_id") Long te_id, @Param("status") Boolean status) {
        String sql = new SQL() {{
            SELECT("count(*)");
            FROM("tb_conversation");
            if (te_id != null) {
                WHERE("te_id=#{te_id}");
            }
            if (status != null) {
                WHERE("con_status=#{status}");
            }
        }}.toString();
        return sql;
    }
}
